package com.xiedafeng.www.view;

import com.xiedafeng.www.controller.RegisterController;
import com.xiedafeng.www.po.User;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class RegisterView {
    Stage stage=new Stage();
    TextField userNameField =new TextField();
    PasswordField passwordField =new PasswordField();
    TextField nameField =new TextField();
    TextField sexField =new TextField();
    TextField birthdayField =new TextField();
    TextField introduceField =new TextField();

    public void create(){
        GridPane gridPane=new GridPane();
        Text userName=new Text();
        userName.setText("账号");
        gridPane.add(userName,0,0);
        Text password=new Text();
        password.setText("密码");
        gridPane.add(password,0,1);
        Text name=new Text();
        name.setText("姓名");
        gridPane.add(name,0,2);
        Text sex=new Text();
        sex.setText("性别");
        gridPane.add(sex,0,3);
        Text birthday=new Text();
        birthday.setText("生日(xx年xx月xx日)");
        gridPane.add(birthday,0,4);
        Text introduce=new Text();
        introduce.setText("个人说明");
        gridPane.add(introduce,0,5);
        Button login=new Button("注册");
        gridPane.add(login,0,6);
        gridPane.add(userNameField,1,0);
        gridPane.add(passwordField,1,1);
        gridPane.add(nameField,1,2);
        gridPane.add(sexField,1,3);
        gridPane.add(birthdayField,1,4);
        gridPane.add(introduceField,1,5);
        gridPane.setAlignment(Pos.CENTER);
        Scene scene=new Scene(gridPane);
        stage.setScene(scene);
        login.setOnMouseClicked(event -> {
            check();
        });
        stage.showAndWait();
    }

    private void check() {
        User user= new User();
        user.setUserName(userNameField.getText());
        user.setPassword(passwordField.getText());
        user.setName(nameField.getText());
        user.setSex(sexField.getText());
        user.setBirthday(birthdayField.getText());
        user.setSelfIntroduce(introduceField.getText());
        RegisterController registerController=new RegisterController();
        try {
            registerController.check(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void close(){
        stage.close();
    }
}
